package com.longrise.android.byjk.plugins.hra.hratabfirst;

import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.android.byjk.R;
import com.longrise.android.byjk.model.CourseDefaultItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/1/4.
 */

public class HraOrderRcvAdapter extends BaseMultiItemQuickAdapter<HraOrderDefaultItem, BaseViewHolder> {


    private OnItemClickListener mListener;
    private List<HraOrderDefaultItem> mItemList = new ArrayList<>();
    public static final int ORDERNUM = 5;


    public HraOrderRcvAdapter(List<HraOrderDefaultItem> data) {
        super(data);
        addItemType(CourseDefaultItem.TYPE1,R.layout.hra_order_null_view);
        addItemType(CourseDefaultItem.TYPE2,R.layout.item_hra_order_rcv);
    }

    public void refreshDatas(List<HraOrderDefaultItem> mDefaultItemList) {
        mItemList.clear();
        mItemList.addAll(mDefaultItemList);
        setNewData(mItemList);
    }

    @Override
    protected void convert(BaseViewHolder helper, HraOrderDefaultItem item) {

        if(HraOrderDefaultItem.TYPE1 == item.getItemType()){
            return ; //默认加载页面 不做处理
        }

        final View convertView = helper.getConvertView();
        final TextView mHraPositon = helper.getView(R.id.tv_hra_position);
        TextView tv_price_type1 = helper.getView(R.id.tv_price_type1);
        TextView tv_price_type2 = helper.getView(R.id.tv_price_type2);
        TextView tv_count_left = helper.getView(R.id.tv_count_left);
        LinearLayout ll_price_type1 = helper.getView(R.id.ll_price_type1);
        LinearLayout ll_price_type2 = helper.getView(R.id.ll_price_type2);
        View view_type1 = helper.getView(R.id.view_type1);
        View view_type2 = helper.getView(R.id.view_type2);


        HraOrderBean hraOrderBean = item.getHraOrderBean();
        String price1 = hraOrderBean.getPriceType1();
        String price2 = hraOrderBean.getPriceType2();
        String stockpeople = hraOrderBean.getLeftCounts();
        final String storeid = hraOrderBean.getStoreId();
        if("0.00".equals(price1)){
            ll_price_type1.setVisibility(View.GONE);
            view_type1.setVisibility(View.GONE);
            if("0".equals(price2)){
                ll_price_type2.setVisibility(View.GONE);
                view_type2.setVisibility(View.GONE);
            }else{
                ll_price_type2.setVisibility(View.VISIBLE);
                view_type2.setVisibility(View.VISIBLE);
                tv_price_type2.setText("¥"+price2);
            }
        }else {
            if("0.00".equals(price2)){
                ll_price_type2.setVisibility(View.GONE);
                view_type2.setVisibility(View.GONE);
            }else{
                view_type1.setVisibility(View.VISIBLE);
                ll_price_type2.setVisibility(View.VISIBLE);
                view_type2.setVisibility(View.VISIBLE);
                tv_price_type2.setText("¥"+price2);
            }
            ll_price_type1.setVisibility(View.VISIBLE);
            view_type1.setVisibility(View.GONE);
            tv_price_type1.setText("¥"+price1);
        }



        mHraPositon.setText(hraOrderBean.getHraName());
        int storePlace = Integer.parseInt(stockpeople);
        if(storePlace > ORDERNUM){
            tv_count_left.setTextColor(Color.parseColor("#FF999999"));
        }else{
            tv_count_left.setTextColor(Color.parseColor("#FFFBA140"));
        }
        tv_count_left.setText("仅剩"+ stockpeople +"席");

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onItemClick(storeid);
                }
            }
        });

        //让最后的item 分割线不显示
        int layoutPosition = helper.getLayoutPosition();
        if (layoutPosition == mItemList.size()) {
            helper.getView(R.id.item_report_line).setVisibility(View.GONE);
        }else{
            helper.getView(R.id.item_report_line).setVisibility(View.VISIBLE);
        }

    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }

    public interface OnItemClickListener {

        void onItemClick(String id);
    }

}
